#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
"""
http://www.careercup.com/question?id=14967793
You are given an input form such as the following
(1, (2, 3), (4, (5, 6), 7))
Each element is either a number or a list (whose elements may also be numbers or other lists).
Output the numbers as they appear, stripped down into a single list.
E.G. (1, 2, 3, 4, 5, 6, 7)

(Complication - how does your code handle the case of ((((5)))) vs just ( 5 ) ? )
"""
import os, re, sys, getopt
import logging
import locale

def flatten(l, out):
    """docstring for flatten"""
    for i in l:
        if type(i) == tuple:
            flatten(i, out)
        else: out.append(i)

if __name__ == '__main__':
    arr = (1, (2, 3), (4, (5, 6), 7))
    out = []

    flatten(arr, out)
    print out
